/*
 * Test.cpp
 *
 *  Created on: 22-01-2012
 *      Author: Jarek
 */


#include "Game.h"

//float myAngle = 0.0f;

void Game::init() {
	fontMain = NULL;
}

void Game::run2d(float delta) {
//	char temp[100];
//	sprintf(temp, "FPS: %.2f", 1.0f/delta);
//	drawFont(fontMain, temp, 0, fontMain->getHeight());

	char text[128];

	static const uint framesNum = 10;
	static const float inv = 1.0f / static_cast<float>(framesNum);
	static float frames[framesNum] = {0};
	static float avgFps = 0.0f;
	static uint index = 0;

	float fps;
	if (delta > 0.0f)
	    fps = 1.0f/delta;
	else
	    fps = 1000.0f;

	frames[index] = fps;
	index = (index+1)%framesNum;
	if (index == 0) {
	    avgFps = 0.0f;
	    for (uint i = 0; i < framesNum; ++i)
	        avgFps += frames[i];
	    avgFps *= inv;
	}

	sprintf(text, "FPS: %.2f (%.2f)", avgFps, fps);
//	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
	drawFont(fontMain, text, 0, fontMain->getHeight(), ALIGN_FONT_LEFT | ALIGN_FONT_TOP, 0.5f, 0.0f);
//	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

//	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	glColor4f(0.0f, 1.0f, 1.0f, 1.0f);
	fillRect(100,700, 100, 100);
//	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
//	drawFont(fontMain, (char*)"JA", screenWidth>>1, screenHeight>>1, ALIGN_FONT_CENTER | ALIGN_FONT_MIDDLE);

	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}

void Game::run3d(float delta) {

//	glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
//	fillRect(0,0,100,100);
//	glTranslatef(200, 0, 0);
//	glTranslatef(0.0f, 0.0f, -6.0f);		//Move up 1.3 Units and -6.0 into the Screen
//	glScalef(0.6f, 0.6f, 0.6f);
//	glRotatef(myAngle, 0.0f, 1.0f, 0.0f);
//	fillTriangle(0, 0, 100, 100);
//	drawPyramide();
//	drawCube(1,1,1,1,1);

//	myAngle += 0.5f;
}

void Game::initFreetype() {

}
